import 'package:flutter/material.dart';
import 'package:huajianshe_app/base/BaseState.dart';
import 'package:huajianshe_app/common/C.dart';

class Btn extends StatelessWidget {

  final String text;
  final double fontSize;
  final Color textColor;
  final Color disabledTextColor;
  final Color backgroundColor;
  final Color disabledBackgroundColor;
  final double? minHeight;
  final double? minWidth;
  final VoidCallback? onPressed;
  final double radius;
  final BorderSide side;
  final EdgeInsetsGeometry padding;

  const Btn({
    Key? key,
    this.text = '',
    this.fontSize = 14,
    this.textColor = Colors.white,
    this.disabledTextColor = Colors.white,
    this.backgroundColor = C.primary,
    this.disabledBackgroundColor = C.primary,
    this.minHeight = 48,
    this.minWidth = double.infinity,
    this.onPressed,
    this.radius = 0,
    this.padding = const EdgeInsets.all(0),
    this.side = BorderSide.none}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    print('$minWidth $minHeight');
    return TextButton(
        child: Text(text, style: TextStyle(fontSize: fontSize),),
        onPressed: onPressed,
        style: ButtonStyle(
          // 文字颜色
          foregroundColor: MaterialStateProperty.resolveWith((states) {
            if (states.contains(MaterialState.disabled)) {
              return disabledTextColor;
            }
            return textColor;
          }),
          // 背景颜色
          backgroundColor: MaterialStateProperty.resolveWith((states) {
            if (states.contains(MaterialState.disabled)) {
              return disabledBackgroundColor;
            }
            return backgroundColor;
          }),
          // // 水波纹
          // overlayColor: MaterialStateProperty.resolveWith((states) {
          //   return (textColor).withOpacity(0.12);
          // }),
          // 按钮最小大小
          minimumSize: (minWidth == null || minHeight == null) ? null : MaterialStateProperty.all<Size>(Size(minWidth!, minHeight!)),
          padding: MaterialStateProperty.all<EdgeInsetsGeometry>(padding),
          shape: MaterialStateProperty.all<OutlinedBorder>(
            RoundedRectangleBorder(
              borderRadius: BorderRadius.circular(radius),
            ),
          ),
          side: MaterialStateProperty.all<BorderSide>(side),
        )
    );
  }



}

